package com.zijie.hosptal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.hosptal.common.Result;
import com.zijie.hosptal.pojo.po.Department;
import com.zijie.hosptal.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    private DepartmentService departmentService;

    @Autowired
    public void setDepartmentService(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @GetMapping
    public Result<?> getAllDepartList(Integer page,Integer limit,Department department){
        Page<Department> departmentPage=Page.of(page,limit);
        departmentPage=departmentService.list(departmentPage, department);
        return Result.success(departmentPage);
    }
    //添加科室
    @PostMapping
    public Result<?> addDepartment(@RequestBody Department department){
        boolean save = departmentService.save(department);
        if (save){
//            System.out.println(department.getName());
            return Result.success();
        }
        return Result.fail("添加失败");
    }
    @DeleteMapping("/{id}")
    public Result<?> deleteDepartment(@PathVariable Integer id){
        boolean removeById = departmentService.removeById(id);
        return removeById?Result.success():Result.fail("删除失败");
    }
    @PutMapping
    public Result<?> updateDepartment(@RequestBody Department department){
        boolean updateById = departmentService.updateById(department);
        return updateById?Result.success():Result.fail("更新失败");
    }
    //只修改科室挂号费
    @PatchMapping
    public Result<?> updateDepartmentPrice(@RequestBody Department department){
        boolean updateById = departmentService.updateDepartmentPrice(department);
        return updateById?Result.success():Result.fail("更新失败");
    }
    @GetMapping("/all")
    public Result<?> getAllDepartmentList(){
        List<Department> list = departmentService.getAll();
        return Result.success(list);
    }

}
